package com.example.demo.Controller;

import com.example.demo.Vo.QuestionAndScore;
import com.example.demo.Vo.Similarity;
import com.example.demo.Vo.VectorResponse;
import com.example.demo.vec.Word2VEC;
import io.netty.util.internal.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RequestMapping("/api")
@RestController
public class ApiController {
    @Autowired
    private Word2VEC vec;
    @RequestMapping("/getvector")
    public VectorResponse getvector(@RequestParam("word")String word){
        if(vec.getWordMap().containsKey(word)) {
            return new VectorResponse(word,vec.getWordVector(word),200,"success");
        }else{
            return new VectorResponse(word,null,1001,"词典中不包含该词");
        }
    }

    @RequestMapping("/getsim")
    public Similarity getsim(@RequestParam("s1")String s1,@RequestParam("s2")String s2){
        double score=vec.cos_sim(s1, s2);
        if(!StringUtil.isNullOrEmpty(s1)&&!StringUtil.isNullOrEmpty(s2)) {
            return new Similarity(s1, s2,score ,200,"success");
        }else{
            return new Similarity(s1,s2,0.0,1002,"参数不全");
        }
    }
}
